package com.justgame.project.service.system.service.basic;

import com.justgame.project.service.system.entity.SysUserSocialInfo;
import com.justgame.project.service.system.query.SysUserSocialInfoQuery;
import com.justgame.project.service.system.wrapper.SysUserSocialInfoWrapper;
import com.justgame.project.base.servcice.IBasicService;
import java.util.Optional;
import org.springframework.util.Assert;
import java.lang.Long;
import org.springframework.lang.NonNull;
import java.lang.Boolean;
import java.lang.String;

/**
 *
 * 用户社交信息表服务自定义查询类
 *
 * @@tableName sys_user_social_info
 * @author Zwb
 */
@SuppressWarnings("all")
public interface BasicSysUserSocialInfoService extends IBasicService<SysUserSocialInfoQuery,SysUserSocialInfo,SysUserSocialInfoWrapper> {

   /**
    * 用户注册后调用创建用户社交信息
    * @param nickname 昵称
    * @param userInfoId 用户信息
    * @param isPrivate 账号敏感社交信息是否隐藏
    */
   default SysUserSocialInfo addByUserRegister(String nickname, Long userInfoId){
      Assert.notNull(userInfoId,"必须提供用户信息");
      Assert.notNull(nickname,"必须提供昵称");
      SysUserSocialInfo sysUserSocialInfo = new SysUserSocialInfo();
      sysUserSocialInfo.setNickname(safeValue(nickname, null));
      sysUserSocialInfo.setUserInfoId(safeValue(userInfoId, null));
      sysUserSocialInfo.setIsPrivate(false);
      save(sysUserSocialInfo);
      return sysUserSocialInfo;
   }

   /**
    * 查询通过字段：用户信息
    * @param userInfoIdIs 用户信息
    */
   default Optional<SysUserSocialInfo> findByUserInfoIdIs(Long userInfoIdIs){
      Assert.notNull(userInfoIdIs,"必须提供用户信息");
      return Optional.ofNullable(getOne(SysUserSocialInfoQuery.builder().getWrapper()
                  .eq(SysUserSocialInfo::getUserInfoId,userInfoIdIs)));
   }

   /**
    * 更新相关字段：昵称
    * @param nickname 昵称
    */
   default boolean updateByNickname(@NonNull SysUserSocialInfo sysUserSocialInfo,String nickname){
      Assert.notNull(nickname,"必须提供昵称");
      Assert.notNull(sysUserSocialInfo.getId(),"必须提供主键ID");
      sysUserSocialInfo.setNickname(safeValue(nickname, null));
      return updateById(sysUserSocialInfo);
   }

   /**
    * 更新相关字段：头像
    * @param avatar 头像
    */
   default boolean updateByAvatar(@NonNull SysUserSocialInfo sysUserSocialInfo,String avatar){
      Assert.notNull(avatar,"必须提供头像");
      Assert.notNull(sysUserSocialInfo.getId(),"必须提供主键ID");
      sysUserSocialInfo.setAvatar(safeValue(avatar, null));
      return updateById(sysUserSocialInfo);
   }

   /**
    * 查询通过字段：昵称
    * @param nicknameIs 昵称
    */
   default long countByNicknameIs(String nicknameIs){
      Assert.notNull(nicknameIs,"必须提供昵称");
      return count(SysUserSocialInfoQuery.builder().getWrapper()
                  .eq(SysUserSocialInfo::getNickname,nicknameIs));
   }

   /**
    * 新增创建
    * @param nickname 昵称
    * @param avatar 头像
    * @param qq QQ账号
    * @param wechatNo 微信账号
    * @param isPrivate 账号敏感社交信息是否隐藏
    * @param userInfoId 用户信息
    * @param description 简介
    */
   default SysUserSocialInfo baseAdd(String nickname, String avatar, String qq, String wechatNo, Boolean isPrivate, Long userInfoId, String description){
      SysUserSocialInfo sysUserSocialInfo = new SysUserSocialInfo();
      sysUserSocialInfo.setNickname(safeValue(nickname, null));
      sysUserSocialInfo.setAvatar(safeValue(avatar, null));
      sysUserSocialInfo.setQq(safeValue(qq, null));
      sysUserSocialInfo.setWechatNo(safeValue(wechatNo, null));
      sysUserSocialInfo.setIsPrivate(safeValue(isPrivate, null));
      sysUserSocialInfo.setUserInfoId(safeValue(userInfoId, null));
      sysUserSocialInfo.setDescription(safeValue(description, null));
      save(sysUserSocialInfo);
      return sysUserSocialInfo;
   }

   /**
    * 更新
    * @param nickname 昵称
    * @param avatar 头像
    * @param qq QQ账号
    * @param wechatNo 微信账号
    * @param isPrivate 账号敏感社交信息是否隐藏
    * @param userInfoId 用户信息
    * @param description 简介
    */
   default boolean baseUpdate(@NonNull SysUserSocialInfo sysUserSocialInfo,String nickname, String avatar, String qq, String wechatNo, Boolean isPrivate, Long userInfoId, String description){
      Assert.notNull(wechatNo,"必须提供微信账号");
      Assert.notNull(description,"必须提供简介");
      Assert.notNull(isPrivate,"必须提供账号敏感社交信息是否隐藏");
      Assert.notNull(userInfoId,"必须提供用户信息");
      Assert.notNull(nickname,"必须提供昵称");
      Assert.notNull(avatar,"必须提供头像");
      Assert.notNull(qq,"必须提供QQ账号");
      Assert.notNull(sysUserSocialInfo.getId(),"必须提供主键ID");
      sysUserSocialInfo.setNickname(safeValue(nickname, null));
      sysUserSocialInfo.setAvatar(safeValue(avatar, null));
      sysUserSocialInfo.setQq(safeValue(qq, null));
      sysUserSocialInfo.setWechatNo(safeValue(wechatNo, null));
      sysUserSocialInfo.setIsPrivate(safeValue(isPrivate, null));
      sysUserSocialInfo.setUserInfoId(safeValue(userInfoId, null));
      sysUserSocialInfo.setDescription(safeValue(description, null));
      return updateById(sysUserSocialInfo);
   }

}